package com.hongyuan.sellfitness.ui.find.activity;

import android.os.Bundle;

import androidx.lifecycle.ViewModelProviders;

import com.hongyuan.sellfitness.R;
import com.hongyuan.sellfitness.base.AppViewModelFactory;
import com.hongyuan.sellfitness.base.Constants;
import com.hongyuan.sellfitness.base.CustomActivity;
import com.hongyuan.sellfitness.databinding.ActivityCircleDetailBinding;
import com.hongyuan.sellfitness.ui.find.view_mode.CircleDetailViewModel;

import me.tatarka.bindingcollectionadapter2.BR;

public class CircleDetailActivity extends CustomActivity<ActivityCircleDetailBinding, CircleDetailViewModel> {

    private String circle_categoryid;

    @Override
    public int initContentView(Bundle savedInstanceState) {
        return R.layout.activity_circle_detail;
    }

    @Override
    public int initVariableId() {
        return BR.viewModel;
    }

    @Override
    public CircleDetailViewModel initViewModel() {
        //使用自定义的ViewModelFactory来创建ViewModel，如果不重写该方法，则默认会调用NetWorkViewModel(@NonNull Application application)构造方法
        AppViewModelFactory factory = AppViewModelFactory.getInstance(getApplication());
        return ViewModelProviders.of(this, factory).get(CircleDetailViewModel.class);
    }

    @Override
    public void initParam() {
        super.initParam();

        circle_categoryid = getBundle().getString("circle_categoryid");
    }

    @Override
    public void initView() {
        super.initView();
        setOnRefresh(binding.refresh,REFRESH_0X3);

        setEnableLoadMore(Constants.GET_CIRCLE_LIST);
        setEnableRefresh(Constants.GET_CIRCLE_LIST);

        binding.comBack.setOnClickListener(view -> finish());
    }

    @Override
    public void initData() {
        super.initData();

        viewModel.setParams("circle_categoryid",circle_categoryid)
                .setParams("circle_state","1");
        viewModel.requestData(Constants.GET_CIRCLE_CATEGORY_INFO);

        viewModel.requestData(Constants.GET_CIRCLE_LIST);
    }
}
